﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Resn.WhuPub.BIL;
using Resn.WhuPub.BLL;
using System.Linq;

namespace Resn.WhuPub.WPFClientUI
{
        /// <summary>
        /// SearchMajorWindow.xaml 的交互逻辑
        /// </summary>
        public partial class SearchMajorPage : Page
        {
                private readonly GlobalManager gm = GlobalManager.Instance;

                public SearchMajorPage()
                {
                        InitializeComponent();
                }

                private void Page_Loaded(object sender, RoutedEventArgs e)
                {
                        gm.MajorName = string.Empty;
                        gm.MajorCode = string.Empty;

                        LayoutRoot.DataContext = gm;
                }

                private void AcceptButton_Click(object sender, RoutedEventArgs e)
                {
                        string name = gm.MajorName.Trim();
                        string code = gm.MajorCode.Trim();

                        try
                        {
                                if (!string.IsNullOrEmpty(name))
                                {
                                        gm.Majors = gm.Majors.Where(i => i.Name.Contains(name)).ToList();
                                }

                                if (!string.IsNullOrEmpty(code))
                                {
                                        gm.Majors = gm.Majors.Where(i => i.Code.Contains(code)).ToList();
                                }
                        }
                        catch (Exception ex)
                        {
                                MessageBox.Show(ex.Message);
                                return;
                        }

                        finally
                        {
                        }

                        NavigationService.GoBack();
                }

                
        }
}